package ling.common.domain.entity;

import com.easy.query.core.annotation.Column;
import com.easy.query.core.annotation.ColumnIgnore;
import com.easy.query.core.annotation.EasyWhereCondition;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import io.swagger.annotations.ApiModelProperty;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

//@Data
public  interface IdEntity<T extends Comparable<T> & Serializable> extends Serializable {

    /** 实体标识
     *
     */
    @ApiModelProperty("实体标识")
    T getId();
    void setId(T id);

    public interface IExtendInfo{
        default public  void ExtendMapSet(String key,Object val){
            getExtendMap().put(key,val);
        }
        @JsonAnyGetter
        public Map<String,Object> getExtendMap();
    }
    @Data
    public class ExtendInfo implements IExtendInfo{
        @Getter(value = AccessLevel.PUBLIC,lazy = true)
        @Setter(AccessLevel.NONE)
        @ColumnIgnore
        private final HashMap<String, Object> extendMap=new HashMap<>();
    }
    @Data
    public class LongId implements IdEntity<Long> ,IExtendInfo{

        @EasyWhereCondition(type = EasyWhereCondition.Condition.EQUAL)
        @Column(primaryKey = true,generatedKey = true)
        Long id;

        @Getter(AccessLevel.NONE)
        @Setter(AccessLevel.NONE)
        @ColumnIgnore
        HashMap<String, Object> extendMap=new HashMap<>();

        public Map<String,Object> getExtendMap(){
            return extendMap;
        }
    }
}
